﻿$(document).ready(function () {
    var pageSize = 15;
    $("#btnSele").click(function () {
        PageClickFunc(1)
    })

    $("#txtPID").focus(function () {
        if ($(this).val() == $(this).attr("default")) {
            $(this).val("");
        }
    })

    $("#txtPID").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }
    })

    PageClickFunc(1)

    function PageClickFunc(pageclickednumber) {
        var StartTime = $("#txtStateTime").val();
        var EndTime = $("#txtEndTime").val();
        var Pid = $("#txtPID").val() == $("#txtPID").attr("default") ? "" : $("#txtPID").val();

        $.ajax({
            type: "post",
            data: { action: "GetList", pageIndex: pageclickednumber, pid: Pid, pageSize: pageSize, StartTime: StartTime, EndTime: EndTime },
            datatype: "json",
            url: "../../Ajax/CommunicationReportAjax.ashx",
            beforSend: function () {
            },
            success: function (data) {
                if (data != null) {
                    var json = $.parseJSON(data).json;
                    var pageCount = $.parseJSON(data).flag;
                    var tbody = "";
                    $.each(json, function (k, v) {
                        tbody += "<tr>"
                        tbody += "<td><lable name='lblTime'>";
                        tbody += v.ReportTime;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblPID'>";
                        tbody += v.PID;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblPName'>";
                        tbody += v.PName;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblNewUserCount'>";
                        tbody += v.NewUserCount;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblNewUserPenect'>";
                        tbody += (v.NewUserPenect * 100).toFixed(2) + "%";
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblActiveUserCount'>";
                        tbody += v.ActiveUserCount;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblActiveUserPenect'>";
                        tbody += (v.ActiveUserPenect * 100).toFixed(2) + "%";
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblPrice'>";
                        tbody += v.Price;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblPagingPrice'>";
                        tbody += v.PagingPrice;
                        tbody += "</lable></td>"; 
                        tbody += "<td><lable name='lblPricePenect'>";
                        tbody += (v.PricePenect * 100).toFixed(2) + "%";
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblChargeCount'>";
                        tbody += v.ChargeCount;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblChargePerCount'>";
                        tbody += v.ChargePerCount;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblMorrowUserPenect'>";
                        tbody += (v.MorrowUserPenect * 100).toFixed(2) + "%";
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblTotalUserCount'>";
                        tbody += v.TotalUserCount;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblTotalChargePrice'>";
                        tbody += v.TotalChargePrice;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblPagingTotalPrice'>";
                        tbody += v.PagingTotalPrice;
                        tbody += "</lable></td>";
                        tbody += "<td><lable name='lblTotalPenect'>";
                        tbody += parseFloat(v.TotalPenect).toFixed(2);
                        tbody += "</lable></td>";
                        tbody += "</tr>"
                    })
                    $("#tb1").empty().append(tbody)
                    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: Math.ceil(pageCount / pageSize), buttonClickCallback: PageClickFunc });
                }
            },
            complete: function () {
            },
            error: function () {
            }
        })
    }
})